package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.DeviceInfo;
import com.example.mapper.DeviceInfoMapper;
import com.example.service.IDeviceInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ysr_xian
 * @since 2022-05-29
 */
@Service
public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements IDeviceInfoService {

    @Autowired private DeviceInfoMapper deviceInfoMapper;

    @Override
    public void saveDeviceInFo(DeviceInfo deviceInfo) {
        if (getOne(new QueryWrapper<DeviceInfo>().eq("device_name", deviceInfo.getDeviceName())) == null) {
            save(deviceInfo);
        } else {
            QueryWrapper<DeviceInfo> queryWrapper = new QueryWrapper<DeviceInfo>().eq("device_name", deviceInfo.getDeviceName());
            update(deviceInfo, queryWrapper);
        }
    }

    @Override
    public DeviceInfo findDeviceByName(String deviceName) {
        return deviceInfoMapper.findDeviceInfoByName(deviceName);
    }

}
